<?php include dirname(__FILE__).'/common/header.php'; ?>

<?php include dirname(__FILE__).'/common/menu.php'; ?>

var attr = {};
attr.ctrlName = '<?php echo $ctrlName; ?>';

/*
| -------------------------------------------------------------------
|  List Grid
| -------------------------------------------------------------------
*/
list.grid = new ZM.GridPanel({
    url: list.baseUrl + attr.ctrlName+'/getCustomerList',
    tbar:[{
        text:'导出过滤顾客',
        cls:'btn-show',
        hidden:!Ext.permission[attr.ctrlName + '/exportCustomerList'.toLowerCase()],
        handler:function() {
            var sortInfo = list.grid.store.getSortState();
            if(sortInfo) {
                list.grid.store.baseParams['sort'] = sortInfo['field'];
                list.grid.store.baseParams['dir'] = sortInfo['direction'];
            }
            location.href = list.baseUrl + attr.ctrlName + '/exportCustomerList?'+ Ext.urlEncode(list.grid.store.baseParams);
        }
    }],
    columns:[
        {header:'ID',dataIndex:'customer_id',filter:{}},
        {header:'红包金额',dataIndex:'gift_money',sort:true,filter:{xtype:'combofield',options:[['','全部'],['0','无'],['1','获得红包']]}},
        {header:'头像',width:120,dataIndex:'headimgurl',renderer:ZM.cellImage},
        {header:'昵称',dataIndex:'nickname',filter:{}},
        {header:'openid',dataIndex:'openid',width:200,filter:{}},
        {header:'性别',dataIndex:'sex',filter:{xtype:'combofield',options:[['','全部'],['0','未知'],[1,'男'],[2,'女']]},renderer:function(val) {
            return ZM.id2name(val,[[0,'未知'],[1,'男'],[2,'女']]);
        }},
        {header:'省份',dataIndex:'province'},
        {header:'城市',dataIndex:'city'},
        {header:'国家',dataIndex:'country'},
        {header:'游戏次数',dataIndex:'lottery_times',sort:true},
        {header:'创建时间',dataIndex:'customer_time_create',width:140,filter:{xtype:'daterangefield'}},
        {header:'游戏时间',dataIndex:'customer_time_lottery',width:140,filter:{xtype:'daterangefield'}},
        {header:'抽奖次数',dataIndex:'times',sort:true},
        {header:'状态',dataIndex:'customer_status',width:65,renderer:function(val) {
           return ZM.status(val == -2 ? '0' : 1);
        },filter:{
            xtype:'combofield',
            options:[['','全部'],['-2','禁用'],['0','激活']]
        }},
        {header:'操作',renderer:function(v,p,r){
            var str = '';
            //str += Ext.rd('查看抽奖历史','fireDetail',r,attr.ctrlName+'/getLotteryHistoryList');
            if(r.json.customer_status == -2) {
                str += Ext.rd('激活','fireEnable',r,attr.ctrlName+'/enableCustomer');
            } else {
                str += Ext.rd('禁用','fireDisable',r,attr.ctrlName+'/disableCustomer');
            }
            return str;
        }}
    ]
});
/*
| -------------------------------------------------------------------
|  List Grid Action
| -------------------------------------------------------------------
*/
list.grid.fireDisable = function(r) {
    var r = r.json;
    Ext.Msg.confirm('确认?','确定要禁用顾客['+r.nickname+']?',function(btn) {
        if(btn != 'no') {
            ZM.ajax({
                url: list.baseUrl + attr.ctrlName+'/disableCustomer',
                params:{customer_id:r.customer_id},
                mask:list.grid,
                success:function(res){
                    ZM.bo.msg('success!',res.detail);
                    list.grid.store.reload();
                }
            });
        }
    });
}

list.grid.fireEnable = function(r) {
    var r = r.json;
    Ext.Msg.confirm('确认?','确定要激活顾客['+r.nickname+']?',function(btn) {
        if(btn != 'no') {
            ZM.ajax({
                url: list.baseUrl + attr.ctrlName+'/enableCustomer',
                params:{customer_id:r.customer_id},
                mask:list.grid,
                success:function(res){
                    ZM.bo.msg('success!',res.detail);
                    list.grid.store.reload();
                }
            });
        }
    });
}

<?php include dirname(__FILE__).'/common/layout.php'; ?>
list.grid.store.load();
<?php include dirname(__FILE__).'/common/footer.php'; ?>